import paddle
import paddle.io as io
from paddle.optimizer import Adam
import numpy as np
import scipy.io as scio


SNR_val = -10
M_val = 25


class MWCdata2(io.Dataset):
    def __init__(self, MatFilePath, test_rule0, test_rule):
        self.x_test = []
        self.label_test = []
        data = scio.loadmat(MatFilePath)
        self.x_test.append(data['x'][test_rule0:test_rule])
        self.label_test.append(data['label'][test_rule0:test_rule])

        self.x_test = paddle.to_tensor(np.vstack(self.x_test), dtype='float64')
        self.label_test = paddle.to_tensor(np.vstack(self.label_test))

        self.len = len(self.x_test)

    def __len__(self):
        return self.len

    def __getitem__(self, idx):
        return self.x_test[idx], self.label_test[idx]


#之后需要再使用DataLoader加载一遍
def load_data(MatFilePath, test_rule0, test_rule):
    # 创建数据集实例
    dataset = MWCdata2(MatFilePath, test_rule0, test_rule)
    return dataset

